import 'package:bxultimate/data/request/organization_request.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:quill_html_editor/quill_html_editor.dart';

import 'state.dart';

class OrganizationAnnouncementPublishController extends GetxController {
  final OrganizationAnnouncementPublishState state =
      OrganizationAnnouncementPublishState();

  TextEditingController titleEditController = TextEditingController();
  TextEditingController descEditController = TextEditingController();

  var text = '';

  QuillEditorController editorController = QuillEditorController();

  final toolbarColor = Colors.grey.shade200;
  final backgroundColor = Colors.white70;
  final toolbarIconColor = Colors.black87;
  final editorTextStyle = const TextStyle(
      fontSize: 18,
      color: Colors.black,
      fontWeight: FontWeight.normal,
      fontFamily: 'Roboto');
  final hintTextStyle = const TextStyle(
      fontSize: 18, color: Colors.black38, fontWeight: FontWeight.normal);

  onTextChanged(String p1) {
    text = p1;
  }

  void publish() async {
    if (titleEditController.text == '') {
      SmartDialog.showNotify(msg: '请输入标题', notifyType: NotifyType.failure);
      return;
    }
    if (descEditController.text == '') {
      SmartDialog.showNotify(msg: '请输入描述', notifyType: NotifyType.failure);
      return;
    }
    if (text == '') {
      SmartDialog.showNotify(msg: '请输入内容', notifyType: NotifyType.failure);
      return;
    }

    await OrganizationRequest.appSendAnnouncement({
      "noticeName": titleEditController.text,
      "noticeDescription": descEditController.text,
      "content": [text],
      "chatRoomId": Get.arguments['id'],
    });

    SmartDialog.showNotify(msg: '发布成功', notifyType: NotifyType.success);
    Get.back();
  }
}
